package com.snopy.reference.phantom;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;

/**
 * @author snopy
 * @version 1.0.0
 * @classname PhantomReferenceDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/16 11:22
 */
public class PhantomReferenceDemo {
    public static void main(String[] args) {
        ReferenceQueue<ClassMemory> queue = new ReferenceQueue<>();
        PhantomReference<ClassMemory> m1 = new PhantomReference<>(new ClassMemory(),queue);
        System.out.println("m1"+m1.get());
        PhantomReference<ClassMemory> m2 = new PhantomReference<>(new ClassMemory(),queue);
        System.out.println("m2"+m2.get());
        PhantomReference<ClassMemory> m3 = new PhantomReference<>(new ClassMemory(),queue);
        System.out.println("m3"+m3.get());
        PhantomReference<ClassMemory> m4 = new PhantomReference<>(new ClassMemory(),queue);
        System.out.println("m4"+m4.get());
    }
}
class ClassMemory{
    private byte[] memory = new byte[1024*1024];
}